package cn.dengta.webapp.user.model;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Common;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

@Getter
public enum Global implements ValueProxyImpl<Global, Integer> {

	/** 国内 */
	HOME(0, "国内"),
	/** 海外 */
	ABROAD(1, "海外"),
	//
	;
	// 定义私有变量
	@EnumValue
	public final Integer value;
	final ValueProxy<Global, Integer> proxy;

	// 构造函数，枚举类型只能为私有
	Global(Integer value, String label) {
		this.value = value;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public static final Global[] CACHE = values();

	public static Global of(@Nullable Integer value) {
		return Common.getEnum(CACHE, Global::getValue, value);
	}

	@Nonnull
	public static Global getOrDefault(@Nullable Global gender) {
		return gender == null ? ABROAD : gender;
	}

}
